package com.cskaoyan.gateway.controller.shopping;

import com.mall.commons.result.ResponseData;
import com.mall.commons.result.ResponseUtil;
import com.mall.order.CancelOrderService;
import com.mall.order.dto.CancelOrderRequest;
import com.mall.order.dto.CancelOrderResponse;
import com.mall.user.annotation.Anonymous;
import com.mall.user.constants.SysRetCodeConstants;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
 * create by heyyon 2020-12-22 10:29
 */
@RestController
public class CancelOrderController {
    @Reference(check = false)
    CancelOrderService cancelOrderService;

    @Anonymous
    @PostMapping("shopping/cancelOrder")
    public ResponseData cancelOrder(@RequestBody Map map) {
        CancelOrderRequest cancelOrderRequest = new CancelOrderRequest();
        String idStr = (String) map.get("orderId");
        cancelOrderRequest.setOrderId(idStr);
        CancelOrderResponse cancelOrderResponse = cancelOrderService.cancelOrderById(cancelOrderRequest);
        if (!cancelOrderResponse.getCode().equals(SysRetCodeConstants.SUCCESS.getCode())) {
            return new ResponseUtil<>().setErrorMsg(cancelOrderResponse.getMsg());
        }
        return new ResponseUtil<>().setData(cancelOrderResponse);
    }
}
